/*
 * Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke
 *
 * This file is part of SeMoLearning.
 *
 * SeMoLearning is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * SeMoLearning is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SeMoLearning.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DBTRASH_H_
#define DBTRASH_H_

#include "semol/core/SemolExp.h" // DLL export/import defines

#include <opencv2/core/core.hpp>

#include <utilite/UMutex.h>
#include <utilite/UThread.h>

#include "semol/core/Node.h"

#include <map>

namespace semol {

class DBDriver;

class SEMOL_EXP DBTrash : public UThread
{
public:
	DBTrash(DBDriver * dbDriver);
	virtual ~DBTrash();

	void asyncSave(Node * s); //ownership transferred
	void asyncSave(Sensor * s); //ownership transferred
	void emptyTrashes(bool async = false);
	double getEmptyTrashesTime() const {return _emptyTrashesTime;}

	std::list<Node *> loadNodes(const std::list<int> & ids);
	std::map<int, Sensor *> loadSensors(const std::set<int> & sensorIds);

private:
	//thread stuff
	virtual void mainLoop();

private:
	UMutex _transactionMutex;
	std::map<int, Node *> _trashNodes;//<id, Node*>
	std::map<int, Sensor *> _trashSensors; //<id, Sensor*>
	UMutex _trashesMutex;
	double _emptyTrashesTime;
	DBDriver * _dbDriver;
};

}

#endif /* DBTRASH_H_ */
